package com.itheima.array;

import java.util.Arrays;
import java.util.Random;
import java.util.Scanner;

/**
 * 随机排名 （倒序输出）
 */
public class ArrayPractise08 {
    public static void main(String[] args) {
        int[] num = new int[5];
        reverseArray(num);
    }

    public static void reverseArray(int[] num) {
        //创建一个数组
        for (int i = 0; i < num.length; i++) {
            Scanner sc = new Scanner(System.in);
            System.out.println("请输入第"+ (i+1) + "个员工的工号");
            int codes = sc.nextInt();
            num[i] = codes;
        }
        //从数组中随机一个索引 然后交换

        int temp = 0;
        for (int i = 0; i < num.length; i++) {
            Random random = new Random();
            //随机一个索引值
            int index = random.nextInt(num.length);
            //随机出来的索引值 跟遍历的数组 依次交换
            temp = num[index];
            num[index] = num[i];
            num[i] = temp;
        }
        System.out.println("输出员工的工号");
        System.out.println(Arrays.toString(num));


    }
}
